/*
 * UIAlert.fx
 *
 * Created on 2009-9-16, 13:58:18
 */

package com.sjtu.fx.tools;

import javafx.scene.CustomNode;

import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;

import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

import javafx.scene.shape.Line;
import javafx.scene.input.MouseEvent;

import javafx.scene.shape.Rectangle;
import javafx.scene.control.Button;

/**
 * @author Administrator
 */

public class UIAlert extends CustomNode{
public var title= "Error";
public var width = 250;
public var height = 120;
public var content = "Something Wrong!";
public var click = false;
public var confirm = false on replace{
    if(confirm){
        confirm = true;
    }else confirm = false;
};
public var type ="inform" on replace{
    if(type == "inform"){
        button.visible = true;
        yes.visible = false;
        no.visible = false;
    }
    if(type == "confirm"){
        button.visible = false;
        yes.visible = true;
        no.visible = true;
    }
};


var icon = ImageView {
    image: Image {
        url: "{__DIR__}icon.png"
    }
    fitWidth: 40
    preserveRatio: true
    smooth: true
    cache: true
    x:15 y:35
    opacity:0.9
}

var info = Text {
    font: Font {size:10 name: "Verdana"}
    fill: Color.rgb(11,51,60)
    content: bind content
    x:60 y:55
};

 var t = Text{
                 content: bind title
                 x: 15 y: 20
                 fill: Color.rgb(11,51,60)
                 font: Font{ size:14 name: "Verdana Bold"}
}

var rec = Rectangle {
           width: 20, height: 20
           arcWidth: 5  arcHeight: 5
           fill: Color.rgb(152, 190, 198)
}
var close = Group{
   translateX:width-30 translateY:5
   content:[
      rec,
      Line {
          startX: 5
          startY: 5
          endX: 15
          endY: 15
          stroke: Color.WHITE
          strokeWidth: 2},
      Line {
          startX: 5
          startY: 15
          endX: 15
          endY: 5
          stroke: Color.WHITE
          strokeWidth: 2},
   ]
   opacity: 0.8
   onMouseEntered: function( e: MouseEvent ):Void {
       rec.fill = Color.RED;
   }
   onMouseExited: function( e: MouseEvent ):Void {
       rec.fill = Color.rgb(152, 190, 198);
   }
   onMouseClicked: function( e: MouseEvent ):Void {
        visible = false;
   }
}//Group

var button = Button {
       text: "OK"
       action: function() {
           visible = false;
       }
       translateX: width/2 -15
       translateY: height - 45
   }

var yes = Button {
       text: "Yes"
       action: function() {
           click = true;
           confirm = true;
           visible = false;
       }
       translateX: width/2 -45
       translateY: height - 45
       visible:false
   }
var no = Button {
       text: "No"
       action: function() {
           click = true;
           confirm = false;
           visible = false;
       }
       translateX: width/2 + 15
       translateY: height - 45
       visible:false
   }

   var panel = Panel {
                width:  bind  width
                height: bind  height
                title:  ""
                translateX: 0
                translateY: 0
   }

override protected function create() : Node {

    Group{
        content:[
            panel,t,
            icon,info,close,button,yes,no


        ]

  }
}

}
